package com.example.network.JSON_parsing;

import com.alibaba.fastjson.JSON;
import com.example.network.entity.Person;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JSON_Fastjson {
    public static Person AnalyticalObject(String json){
        Person person = JSON.parseObject(json, Person.class);

        return person;
    }
    /**
     * 解析对象数组
     */
    public static List<Person> AnalyticalArrayObject(String json){
        List<Person> people = JSON.parseArray(json,Person.class);
        return people;
    }
    public static Map<String,Person> AnalyticalMapObject(String json){
        Map<String,Person> map = new HashMap<String,Person>();
        map=(Map<String, Person>) JSON.parse(json);

        return map;
    }


    public static String toJson(Object o){
        return JSON.toJSONString(o);
    }
}
